from lxml.html import etree

tree = etree.parse('a.html')

# res = tree.xpath('/html/body/ul/li/a/text()')
# res = tree.xpath('/html/body/ul/li[1]/a/text()')  # xpath数数从1开始
# res = tree.xpath("/html/body/ol/li/a[@href='dapao']/text()")
# print(res)

# ol_li_list = tree.xpath("/html/body/ol/li")
# print([li.xpath("./a/text()") for li in ol_li_list])  # 当前节点
# print([li.xpath("./a/@href") for li in ol_li_list])  # 当前属性值
